package com.mpsc.api.unit;


import com.mpsc.api.bean.UserInfoEntity;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;

public class StringUtil {
    public static void main(String[] args) {
//        String taskIds = "12312,";
//        String[] arrTaskIds = taskIds.split(",");
//        System.out.println(arrTaskIds[0]);
//        System.out.println(arrTaskIds.length);

        List<UserInfoEntity> userList = new ArrayList<>();
        for (int i = 0; i < 10001; i++) {
            userList.add(new UserInfoEntity());
        }

        List<List<UserInfoEntity>> lists = subList(userList, 1000);
        System.out.println(lists.size());


    }

    /**
     * 拼接字符创
     */
    public static String join(CharSequence delimiter, CharSequence... elements) {
        Objects.requireNonNull(delimiter);
        Objects.requireNonNull(elements);
        // Number of elements not likely worth Arrays.stream overhead.
        StringJoiner joiner = new StringJoiner(delimiter);
        for (CharSequence cs : elements) {
            joiner.add(cs);
        }
        return joiner.toString();
    }


    public static <T> List<List<T>> subList(List<T> list, int size) {
        List<List<T>> resultList = new ArrayList<>();
        if (!CollectionUtils.isEmpty(list)) {
            List<T> result = new ArrayList<>();
            resultList.add(result);
            for (int i = 0, len = list.size(); i < len; i++) {
                result.add(list.get(i));
                if (result.size() == size && i != len - 1) {
                    result = new ArrayList<>();
                    resultList.add(result);
                }
            }
        }
        return resultList;
    }


}




